import 'package:syn_4s/core/model/base/api_result_data.dart';

import '../model/base/base_model.dart';
import '../model/project_model.dart';
import '../utils/dio_utils.dart';

class MainRequest {
  // static Future<ApiResultData<T>> getData<T extends BaseModel>(
  //     {required String projCode,
  //     required String synProj,
  //     required T Function(Map<String, dynamic>) fromJsonT,
  //     String? keyWord}) async {
  //   // 1.发送网络请求
  //   final url = "/api/Dashboards?projCode=$projCode&synProj=$synProj";
  //   final result = await DioUtils.instance.requestBaseUrl(url);
  //   ApiResultData<T> apiResultData =
  //       ApiResultData<T>.fromJson(result, fromJsonT);
  //   // 2.json转model
  //   return apiResultData;
  // }

  static Future getData(
      {required String projCode,
      required String synProj,
      String? keyWord}) async {
    // 1.发送网络请求
    String url = "/api/Dashboards?projCode=$projCode&synProj=$synProj";
    if(keyWord != null && keyWord.isNotEmpty){
      url += "&keyWord=$keyWord";
    }
    final result = await DioUtils.instance.requestBaseUrl(url);

    // 2.json转model
    return result;
  }

  static Future<ApiResultData<List<ProjectModel>>> getProjects(
      String typeKey) async {
    final result = await DioUtils.instance
        .requestBaseUrl("/api/utils/combos?typeKey=$typeKey");
    ApiResultData<List<ProjectModel>> apiResultData =
    ApiResultData<List<ProjectModel>>.fromListJson(
        result,
            (data) => data
            .map(
                (item) => ProjectModel.fromJson(item as Map<String, dynamic>))
            .toList());
    // 2.json转model
    return apiResultData;
  }
}
